<template>
    <div class="goodDetail">
        <div class="top">
            <div class="back-icon-box" @click="$router.back()">
                <van-icon class="icon" name="arrow-left" />
            </div>
            <van-swipe :autoplay="3000">
                <van-swipe-item v-for="item in detail.pics" :key="item.id">
                    <img :src="item.pic" />
                </van-swipe-item>
            </van-swipe>
            <div class="top-detail">
                <h3>{{baseInfo.name}}</h3>
                <span class="desc">{{baseInfo.characteristic}}</span>
                <section>
                    <span class="minPrice">底价<em>￥{{baseInfo.minPrice}}</em><i>原价￥{{baseInfo.originalPrice}}</i></span>
                    <span>库存{{baseInfo.stores}}</span>
                </section>
            </div>
        </div>
        <my-good-detail 
        :content="detail.content" 
        :reps="reps"
        ></my-good-detail>
        <my-buy @changeshow="changeShow" v-if="$route.query.type !== 'kj'"></my-buy>
        <div class="bargin" v-else>立即发起砍价，最低可砍到1元</div>
        <van-popup v-model:show="show" position="bottom" :style="{ height: '40%' }" >
            <div>
                <img class="pop-img" :src="baseInfo.pic" alt="">
                <section>
                    <h3>{{baseInfo.name}}</h3>
                    <span>￥{{baseInfo.minPrice}}</span>
                </section>
                <van-icon name="cross" />
            </div>
            <div>
                <h3>{{size.name}}</h3>
                <ul>
                    <li v-for="item in size.childsCurGoods" :key="item.id">{{item.name}}</li>
                </ul>
            </div>
            <div>
                <span>购买数量</span>
                <van-stepper v-model="value" />
            </div>
        </van-popup>
    </div>
</template>

<script>
import { goodDetail, getRep } from '@/api/home'
import myGoodDetail from '@/components/myGoodDetail/myGoodDetail'
import myBuy from '@/components/myBuy/myBuy'
export default {
    name: '',
    data() { 
        return {
            detail: {},
            baseInfo: {},
            reps: [],
            show: false,
            value: 1,
            size: {}
        }
    },
    components: {
        myGoodDetail,
        myBuy
    },
    created() {
        // 请求商品详情信息
        goodDetail(this.$route.params.id).then(res => {
            this.detail = res.data
            this.baseInfo = res.data.basicInfo
            this.size = res.data.properties[0]
        }) 

        // 请求商品评价信息
        getRep(this.$route.params.id).then(res => {
            // console.log(res);
            this.reps = res.data
        })

    },

    methods: {
        changeShow(bool) {
            this.show = bool
        }
    }
}
</script>

<style scoped lang="scss">
.goodDetail {
    height: 100%;
    overflow: auto;
    padding-bottom: 100px;
}
img {
    width: 100%;
    height: 750px;
}
.top {
    margin-bottom: 30px;
    position: relative;
}
.back-icon-box {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 6px;
    border: 1px solid #fff;
    border-radius: 50%;
    z-index: 5;
    color: #666;
    .icon {
        background-color: #fff;
        border-radius: 50%;
    }

}
.top-detail {
    padding-top: 40px;
    padding-left: 30px;
    padding-bottom: 20px;
    background-color: #fff;
    h3 {
        font-size: 36px;
        color: #333;
    }
    .desc {
        font-size: 24px;
        color: #b2b2b2;
    }
    section {
        display: flex;
        width: 100%;
        justify-content: space-between;
        font-size: 24px;
        margin-top: 40px;
        padding-right: 20px;
        color: #b2b2b2;
        .minPrice {
            color: #CC0C0C;
            em {
                font-size: 30px;
                margin-right: 40px;
            }
            i {
            color: #b2b2b2;}
        }
    }
}
.bargin {
    background-color: #CC0C0C;
    color: #fff;
    text-align: center;
    width: 100%;
    height: 100px;
    line-height: 100px;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 10;
    font-size: 26px;
}
.pop-img {
    width: 126px;
    height: 126px;
    margin-left: 30px;
    margin-top: 30px;
}
</style>